package com.zxc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.dao.SysPermissionMapper;
import com.zxc.entity.SysPermission;
import com.zxc.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {
    @Autowired
    private SysPermissionMapper sysPermissionMapper;

    @Override
    public int getAllSysPermissionCount(Integer roleId) {
        int count = sysPermissionMapper.selectAllPermissionCount(roleId);
        return count;

    }

    @Override
    public List<SysPermission> getSysPermissionList(Integer pageNo, Integer pageSize, Integer roleId) {
        List<SysPermission> sysPermissionList = sysPermissionMapper.selectAllPermissionAndRoleId(pageNo,pageSize,roleId);
        return sysPermissionList;
    }

    @Override
    @Transactional
    public int deleteByIds(String[] id) {
        int result =  sysPermissionMapper.deleteBatchIds(Arrays.asList(id));
        return result;
    }

    @Override
    @Transactional
    public int saveSysPermission(SysPermission sysPermission) {
        int result = sysPermissionMapper.insert(sysPermission);
        return result;
    }

    @Override
    public SysPermission getSysPermissionById(Integer id) {
        SysPermission sysPermission = sysPermissionMapper.selectById(id);
        return sysPermission;
    }
}
